<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<body>
<h1><span th:text="${test}"></span>直接从model拿的数据</h1>
<p>[[${test1}]]<a onclick="aa();">点我</a></p>
<input id="test" name="test" value="10"/>
<input id="test1" name="test1" value="10"/>
<p><a onclick="bb();">点我测试</a></p>
<select id="selectId" onchange="cc(this.id)">
    <option value="1">选择1</option>
    <option value="2">选择2</option>
    <option value="3">选择3</option>
</select>
<p><input id="ind"/><a onclick="indx()">测试最后一位</a></p>
<label id="imgsize"></label>


<form id="testForm">
    <input name="b"/>
    <input name="b"/>
    <input name="b"/>
    <input type="button" value="提交" onclick="fff();"/>
</form>

<!--<script type="text/javascript" th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}"></script>
<script th:inline="javascript">
    var test = [[${test}]];
    console.log(test);
</script>-->
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
    var a = "全局变量";
    var test = window.location.host;

    function fff() {
        console.log("form表单数据" + $("#testForm").serialize());
    }

    function aa() {
        var b = a + "test";
        a = "11111";
        alert(a);
        alert(b);
        alert(test);
    }

    function bb() {
        var value = document.getElementById("test").value;
        document.getElementById("imgsize").innerText = value;
    }

    function cc(e) {
        var objS = document.getElementById(e);
        var typeVal = objS.options[objS.selectedIndex].value;
        console.log("这是类型：" + typeVal);
    }


    //转义表情
    function utf16toEntities(str) {
        var patt = /[\ud800-\udbff][\udc00-\udfff]/g;
        // 检测utf16字符正则
        str = str.replace(patt, function(char) {
            var H, L, code;
            if (char.length === 2) {
                H = char.charCodeAt(0);
                // 取出高位
                L = char.charCodeAt(1);
                // 取出低位
                code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00;
                // 转换算法
                return "&#" + code + ";";
            } else {
                return char;
            }
        });
        return str;
    }

    function indx() {
        var aa = document.getElementById("ind").value;
        alert(aa.lastIndexOf(","));
    }

</script>
</body>
</html>